package com.wrupple.muba.catalogs.client.module.services.logic.impl;

import java.io.IOException;

import com.google.inject.Inject;
import com.wrupple.muba.catalogs.client.module.services.CatalogSummarySerializer;
import com.wrupple.muba.common.client.JSOHelper;
import com.wrupple.muba.common.domain.FilterData;
import com.wrupple.vegetate.client.module.services.logic.FilterDataSerializationService;
import com.wrupple.vegetate.domain.CatalogResponseContract;

public class CatalogSummarySerializerImpl implements CatalogSummarySerializer {

	FilterDataSerializationService fService;
	
	@Inject
	public CatalogSummarySerializerImpl(FilterDataSerializationService fService) {
		super();
		this.fService = fService;
	}

	@Override
	public CatalogResponseContract deserialize(String string) {
		if(string ==null){
			return null;
		}
		JsCatalogResponseContract c = JSOHelper.eval(string).cast();
		return c;
	}

	@Override
	public String serialize(FilterData object) {
		try {
			return fService.serialize(object);
		} catch (IOException e) {
			return null;
		}
	}

}
